package com.vpx.server.utils;

import com.vpx.server.bean.info.base.UserInfo;
import com.vpx.server.framework.authority.SessionInfo;
import com.vpx.server.framework.authority.SessionUser;
import com.vpx.server.framework.authority.SessionUtil;

/**
 * 该帮助类主要用于将登录后的用户信息保存在线程变量中，
 * 方便提取登录用户信息
 *
 * @author: York.Yu
 * @date: 2017/5/3
 */
public class UserLoginUtils {
    /**
     * 获取userLogin对象
     *
     * @return
     */
    public static UserInfo getCurrentUser() {
        UserInfo info = new UserInfo();
        SessionInfo sessionInfo = SessionUtil.getSession();
        if (sessionInfo != null) {
            SessionUser user = sessionInfo.getSessionUser();
            if (user != null) {
                info.from(user);
                return info;
            }
        }
        return null;
    }
    
    public static Long getCurrentUserId() {
        SessionInfo sessionInfo = SessionUtil.getSession();
        if(sessionInfo == null) {
        	return null;
        }
        SessionUser user = sessionInfo.getSessionUser();
        if (user == null) {
        	return null;
        }	
        return user.getId();
    }
}
